package com.ytjj.qmyx.admin.service.impl;

import com.github.pagehelper.PageHelper;
import com.ytjj.common.api.CommonPage;
import com.ytjj.qmyx.admin.dao.OrderNoteDao;
import com.ytjj.qmyx.admin.model.Admin;
import com.ytjj.qmyx.admin.model.request.OrderNoteRequest;
import com.ytjj.qmyx.admin.model.response.OrderNoteResponse;
import com.ytjj.qmyx.admin.service.MemberService;
import com.ytjj.qmyx.admin.service.OrderNoteService;
import com.ytjj.qmyx.mall.model.OrderNote;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class OrderNoteServiceImpl implements OrderNoteService {

    @Autowired
    private OrderNoteDao orderNoteDao;

    @Autowired
    private MemberService memberService;


    @Override
    public CommonPage<OrderNoteResponse> getOrderNoteList(OrderNoteRequest orderNoteRequest) {
        PageHelper.startPage(orderNoteRequest.getPageNum(), orderNoteRequest.getPageSize());
        List<OrderNoteResponse> pageList = orderNoteDao.getOrderNoteList(orderNoteRequest.getOrderInfoId());
        return CommonPage.restPage(pageList);
    }

    @Override
    public int insertOrderNote(OrderNote orderNote) {
        orderNote.setCreateTime(new Date());
        Admin admin = memberService.getAdmin();
        orderNote.setAdminId(admin.getId());
        return orderNoteDao.insertOrderNote(orderNote);
    }

    @Override
    public List<OrderNoteResponse> getOrderServiceRemark(Integer orderInfoId) {
        List<OrderNoteResponse> notes = new ArrayList<>();
        List<OrderNoteResponse> responses =  orderNoteDao.getOrderServiceRemark(orderInfoId);
        notes.addAll(responses);
        return responses;
    }
}
